<?php

/**

 * 优惠券服务层

 * @author lee

 */

namespace app\common\service;

use app\common\model\Coupon AS CouponModel;
use app\common\model\CouponMe AS CouponMeModel;

class Coupon extends Base
{
    /**
     * 获取优惠券列表
     * @param array  $where 查询条件
     * @param string $field 查询的字段
     * @param string $limit 分页条件
     * @param string $order 排序条件
     */
    public function coupon($where, $limit = '', $append_field="", $order)
    {
		//pbegin<$ptime,
        //pend>$ptime
        $field = 'id,coupon_name,description,offset_price,limit_price,scope,valid_time,register_time,pbegin,pend';
        if($append_field){
            $field=$field.','.$append_field;
        }
        $list= CouponModel::field($field)->where($where)->append(['pbegin_txt','pend_txt'])->order($order)->limit($limit)->select()->toArray();

        return $list;

    }

    /**
     * 查询优惠劵
     */
    public function getCouponMe($where,$field = 'id,coupon_id', $order="id desc")
    {
        return CouponMeModel::field($field) ->where($where)->order($order)->select()->toArray();
    }
}

